/**
 * 
 */
package ua.lviv.franko.mlsFunctions.twoDimension;

/**
 * @author marko
 * 
 */
public class Particle {
	public static final double	EPS	= 0.00000000000000001;
	protected double			xi;
	protected double			yi;
	protected double			rho;
	protected int				position;

	public Particle() {
		xi = 0.0;
		yi = 0.0;
		rho = 0.0;
		position = 0;
	}

	public Particle(double xi, double yi, double rho) {
		this.xi = xi;
		this.yi = yi;
		this.rho = rho;
		this.position = -1;
	}

	public Particle(double xi, double yi, double rho, int position) {
		super();
		this.xi = xi;
		this.yi = yi;
		this.rho = rho;
		this.position = position;
	}

	public double getRho() {
		return rho;
	}

	public double getXi() {
		return xi;
	}

	public double getYi() {
		return yi;
	}

	public double lengthTo(Particle p) {
		return Math.sqrt((p.xi - xi) * (p.xi - xi) + (p.yi - yi) * (p.yi - yi));
	}

	public void setRho(double rho) {
		this.rho = rho;
	}

	public void setXi(double xi) {
		this.xi = xi;
	}

	public void setYi(double yi) {
		this.yi = yi;
	}

	public void setPosition(int position) {
		this.position = position;
	}

	public int getPosition() {
		return position;
	}

	public void increasPosition(int byHowMuch) {
		position += byHowMuch;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(rho);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(xi);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(yi);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Particle)) {
			return false;
		}
		Particle other = (Particle) obj;
		if (Math.abs(rho - other.rho) > EPS) {
			return false;
		}
		if (Math.abs(xi - other.xi) > EPS) {
			return false;
		}
		if (Math.abs(yi - other.yi) > EPS) {
			return false;
		}
		return true;
	}

	// @Override
	// public boolean equals(Object obj) {
	// if(obj instanceof Particle){
	// Particle p = (Particle) obj;
	// return
	// }else{
	// return false;
	// }
	// }

}
